<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>ActiveModel::Validations::Callbacks</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            ActiveModel::Validations::Callbacks 
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/activemodel/lib/active_model/validations/callbacks_rb.html">activemodel/lib/active_model/validations/callbacks.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<h2 id="label-Active+Model+Validation+Callbacks">Active Model Validation <a href="Callbacks.html">Callbacks</a></h2>

<p>Provides an interface for any class to have <code>before_validation</code>
and <code>after_validation</code> callbacks.</p>

<p>First, include <a
href="Callbacks.html">ActiveModel::Validations::Callbacks</a> from the
class you are creating:</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">MyModel</span>
  <span class="ruby-identifier">include</span> <span class="ruby-constant">ActiveModel</span><span class="ruby-operator">::</span><span class="ruby-constant">Validations</span><span class="ruby-operator">::</span><span class="ruby-constant">Callbacks</span>

  <span class="ruby-identifier">before_validation</span> :<span class="ruby-identifier">do_stuff_before_validation</span>
  <span class="ruby-identifier">after_validation</span>  :<span class="ruby-identifier">do_stuff_after_validation</span>
<span class="ruby-keyword">end</span>
</pre>

<p>Like other <code>before_*</code> callbacks if
<code>before_validation</code> returns <code>false</code> then
<code>valid?</code> will not be called.</p>

    </div>
  


  


  
  


  
    <!-- Namespace -->
    <div class="sectiontitle">Namespace</div>
    <ul>
      
        <li>
          <span class="type">MODULE</span>
          <a href="Callbacks/ClassMethods.html">ActiveModel::Validations::Callbacks::ClassMethods</a>
        </li>
      
    </ul>
  


  

  
    <!-- Includes -->
    <div class="sectiontitle">Included Modules</div>
    <ul>
      
        <li>
          
            <a href="../../ActiveSupport/Callbacks.html">
              ActiveSupport::Callbacks
            </a>
          
        </li>
      
    </ul>
  



  

    

    

    


    


    <!-- Methods -->
              </div>

    </div>
  </body>
</html>    